package org.wdcode.back.tag.text;

import org.apache.struts2.util.TextProviderHelper;
import org.wdcode.common.constants.StringConstants;
import org.wdcode.common.util.CommonUtil;

/**
 * 扩展struts2 TextTag
 * @author WD
 * @since JDK6
 * @version 1.0 2010-03-17
 */
public class TextTag extends org.apache.struts2.views.jsp.TextTag {
	// 序列化ID
	private static final long	serialVersionUID	= 5930626629414166733L;

	/**
	 * 重写方法
	 */
	@Override
	protected void populateParams() {
		// 解析名
		name = getStack().findString(name);
		// 判断去掉[]
		if (!CommonUtil.isEmpty(name) && (name.indexOf("[") > -1 || name.indexOf("]") > -1)) {
			name = name.replaceAll("[\\[\\]]", "");
		}
		// 判断名不为空 并且有,分割
		if (!CommonUtil.isEmpty(name) && name.indexOf(StringConstants.COMMA) > -1) {
			// 获得数组
			String[] val = name.split(StringConstants.COMMA);
			// 设置字符串缓存类
			StringBuilder sb = new StringBuilder();
			// 循环
			for (int i = 0; i < val.length; i++) {
				// 添加内容
				sb.append(TextProviderHelper.getText(val[i], StringConstants.EMPTY, getStack()));
			}
			// 设置属性
			name = sb.toString();
		}
		// 调用父方法
		super.populateParams();

	}
}
